﻿using System;

namespace UniRx
{
	// Token: 0x020001F8 RID: 504
	public static class Disposable
	{
		// Token: 0x06000AAE RID: 2734 RVA: 0x00038F7C File Offset: 0x0003737C
		public static IDisposable Create(Action disposeAction)
		{
			return new Disposable.AnonymousDisposable(disposeAction);
		}

		// Token: 0x06000AAF RID: 2735 RVA: 0x00038F84 File Offset: 0x00037384
		public static IDisposable CreateWithState<TState>(TState state, Action<TState> disposeAction)
		{
			return new Disposable.AnonymousDisposable<TState>(state, disposeAction);
		}

		// Token: 0x040006EA RID: 1770
		public static readonly IDisposable Empty = Disposable.EmptyDisposable.Singleton;

		// Token: 0x020001F9 RID: 505
		private class EmptyDisposable : IDisposable
		{
			// Token: 0x06000AB1 RID: 2737 RVA: 0x00038F99 File Offset: 0x00037399
			private EmptyDisposable()
			{
			}

			// Token: 0x06000AB2 RID: 2738 RVA: 0x00038FA1 File Offset: 0x000373A1
			public void Dispose()
			{
			}

			// Token: 0x040006EB RID: 1771
			public static Disposable.EmptyDisposable Singleton = new Disposable.EmptyDisposable();
		}

		// Token: 0x020001FA RID: 506
		private class AnonymousDisposable : IDisposable
		{
			// Token: 0x06000AB4 RID: 2740 RVA: 0x00038FAF File Offset: 0x000373AF
			public AnonymousDisposable(Action dispose)
			{
				this.dispose = dispose;
			}

			// Token: 0x06000AB5 RID: 2741 RVA: 0x00038FBE File Offset: 0x000373BE
			public void Dispose()
			{
				if (!this.isDisposed)
				{
					this.isDisposed = true;
					this.dispose();
				}
			}

			// Token: 0x040006EC RID: 1772
			private bool isDisposed;

			// Token: 0x040006ED RID: 1773
			private readonly Action dispose;
		}

		// Token: 0x020001FB RID: 507
		private class AnonymousDisposable<T> : IDisposable
		{
			// Token: 0x06000AB6 RID: 2742 RVA: 0x00038FDD File Offset: 0x000373DD
			public AnonymousDisposable(T state, Action<T> dispose)
			{
				this.state = state;
				this.dispose = dispose;
			}

			// Token: 0x06000AB7 RID: 2743 RVA: 0x00038FF3 File Offset: 0x000373F3
			public void Dispose()
			{
				if (!this.isDisposed)
				{
					this.isDisposed = true;
					this.dispose(this.state);
				}
			}

			// Token: 0x040006EE RID: 1774
			private bool isDisposed;

			// Token: 0x040006EF RID: 1775
			private readonly T state;

			// Token: 0x040006F0 RID: 1776
			private readonly Action<T> dispose;
		}
	}
}
